import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'pressureReportM',
  state: {
    sceneList: [],
    templateList: [],
  },
  effects: {
    //查询报告列表
    *queryList({ payload, callback }, { call, put }) {
      const res = yield call(api.pressureReport.queryList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback();
        message.error(res ? res.msg || '查询报告列表失败!' : '查询报告列表失败!');
      }
    },
    //查询模板列表
    *getScenes({ payload }, { call, put }) {
      const res = yield call(api.sceneSettings.getScenes, payload);
      if (res && res?.code === 0) {
        let tempArr = (res.data || []).map((item) => {
          return { value: item.value + '', title: item.display };
        });
        yield put({
          type: 'save',
          payload: {
            sceneList: tempArr,
          },
        });
      }
    },
    // 获取测试报告情景 下拉列表
    *getTemplate({ payload }, { call, put }) {
      const res = yield call(api.sceneSettings.getModels, {
        userName: 'default_maat_user_in_evar',
        orgCode: 'ZCTGB',
        systemCode: 'maat',
      });
      if (res && res?.code === 0) {
        let tempArr = (res.data || []).map((item) => {
          return { value: item.ID + '', title: item.C_TEMPLATE_NAME };
        });
        yield put({
          type: 'save',
          payload: {
            templateList: tempArr,
          },
        });
      }
    },
    // 更新未读消息
    *updateUnreadDate({ payload }, { call, put }) {
      const res = yield call(api.updateUnreadDate, payload);
      if (!res || res.code != 0) {
        message.error(`更新未读消息失败，失败原因：${res?.msg}`);
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
